package org.quasar.airNova.presentationLayer;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class EmailFrame extends JFrame {

	private JPanel contentPane;
	private JTextField receptor;

//	/**
//	 * Launch the application.
//	 */
//	public static void main(String[] args) {
//		EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				try {
//					EmailFrame frame = new EmailFrame();
//					frame.setVisible(true);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		});
//	}

	/**
	 * Create the frame.
	 * @param text 
	 */
	public EmailFrame(final String text) {
		this.setVisible(true);
		setTitle("Novo Email");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		JLabel lblReceptor = new JLabel("Receptor:");
		lblReceptor.setBounds(38, 11, 86, 14);
		contentPane.add(lblReceptor);
		
		receptor = new JTextField();
		receptor.setText("<Coloque aqui o receptor>");
		receptor.setBounds(118, 8, 283, 20);
		contentPane.add(receptor);
		receptor.setColumns(10);
		
		JLabel lblConteudo = new JLabel("Conteudo:");
		lblConteudo.setBounds(38, 44, 56, 14);
		contentPane.add(lblConteudo);
		
		JButton btnNewButton = new JButton("Enviar");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				sendEmail(text);
			}

			
		});
		btnNewButton.setBounds(48, 231, 89, 23);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("Cancelar");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				showDownFrame();
			}

			
		});
		btnNewButton_1.setBounds(147, 231, 89, 23);
		contentPane.add(btnNewButton_1);
		
		JTextArea textArea = new JTextArea();
		textArea.setText(text);
		textArea.setEditable(false);
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);
		textArea.setBounds(38, 69, 363, 136);
		contentPane.add(textArea);
	}
	private void showDownFrame() {
		this.dispose();
	}
	private void sendEmail(String text) {
		SendMailTLS.sendEmail(receptor.getText(), text);
		this.dispose();
	}
}
